package com.huike.service.system.impl;

import com.github.pagehelper.PageHelper;
import com.huike.dto.SysPageQueryDTO;
import com.huike.dto.SysRolePageQueryDTO;
import com.huike.mapper.system.SysRoleMapper;
import com.huike.pojo.SysRole;
import com.huike.pojo.User;
import com.huike.result.PageResult;
import com.huike.service.system.SysRoleService;
import com.huike.vo.SysRolePageQueryVO;
import com.huike.vo.SysUserPageVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Autowired
    private SysRoleMapper sysRoleMapper;

    /**
     * 分页查询角色
     *
     * @param queryDTO
     * @return
     */
    @Override
    public PageResult RolePageQuey(SysRolePageQueryDTO queryDTO) {
        if (null == queryDTO ){
            log.error("参数为空");
        }
        if (null == queryDTO.getPageSize() || null == queryDTO.getPageNum() || queryDTO.getPageNum() <= 0 || queryDTO.getPageSize() <= 0) {
            queryDTO.setPageNum(1);
            queryDTO.setPageSize(10);
        }
        PageHelper.startPage(queryDTO.getPageNum(), queryDTO.getPageSize());

        List<SysRolePageQueryVO> page = sysRoleMapper.selectRoleList(queryDTO);
        PageResult pageResult = new PageResult();
        pageResult.setRows(page);
        pageResult.setTotal(page.size());
        pageResult.setCode(200);
        pageResult.setMsg("查询成功");

        return pageResult ;
    }

    /**
     * 修改角色状态
     *
     * @param status
     */
    @Override
    public void changeStatus(Integer status) {
        sysRoleMapper.changeStatus(status);
        log.info("修改角色状态成功");
    }
}
